package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.Customer;
import com.pgybook.db.entity.domain.CustomerEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface CustomerMapper {
    int countByExample(CustomerEx example);

    int deleteByExample(CustomerEx example);

    @Delete({
            "delete from customer",
            "where CUSTID = #{custid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long custid);

    @Insert({
            "insert into customer (CUSTGRADEID, EMAIL, ",
            "PASSWORD, BORROWDAYS, ",
            "MOBILE1, MOBILE2, ",
            "PHONE, PRVID, LIBID, ",
            "CUSTCODE, ADDRESS, ",
            "NAME, ALIAS, RECOMMEMAIL, ",
            "WEIBOACCOUNT, WEIXINACCOUNT, ",
            "STATUS, LASTSUCCESSLOGINTIME, ",
            "LOGINFAILCOUNT, BOOKCOINREWARDACCTBALANCE, ",
            "BOOKCOINACCTCASHBALANCE, DEPOSITBALANCE)",
            "values (#{custgradeid,jdbcType=INTEGER}, #{email,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=VARCHAR}, #{borrowdays,jdbcType=INTEGER}, ",
            "#{mobile1,jdbcType=VARCHAR}, #{mobile2,jdbcType=VARCHAR}, ",
            "#{phone,jdbcType=VARCHAR}, #{prvid,jdbcType=INTEGER}, #{libid,jdbcType=INTEGER}, ",
            "#{custcode,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
            "#{name,jdbcType=VARCHAR}, #{alias,jdbcType=VARCHAR}, #{recommemail,jdbcType=VARCHAR}, ",
            "#{weiboaccount,jdbcType=VARCHAR}, #{weixinaccount,jdbcType=VARCHAR}, ",
            "#{status,jdbcType=INTEGER}, #{lastsuccesslogintime,jdbcType=TIMESTAMP}, ",
            "#{loginfailcount,jdbcType=INTEGER}, #{bookcoinrewardacctbalance,jdbcType=DECIMAL}, ",
            "#{bookcoinacctcashbalance,jdbcType=DECIMAL}, #{depositbalance,jdbcType=DECIMAL})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "custid", before = false, resultType = Long.class)
    int insert(Customer record);

    int insertSelective(Customer record);

    List<Customer> selectByExample(CustomerEx example);

    @Select({
            "select",
            "CUSTID, CUSTGRADEID, EMAIL, PASSWORD, BORROWDAYS, MOBILE1, MOBILE2, PHONE, PRVID, ",
            "LIBID, CUSTCODE, ADDRESS, NAME, ALIAS, RECOMMEMAIL, WEIBOACCOUNT, WEIXINACCOUNT, ",
            "STATUS, LASTSUCCESSLOGINTIME, LOGINFAILCOUNT, BOOKCOINREWARDACCTBALANCE, BOOKCOINACCTCASHBALANCE, ",
            "DEPOSITBALANCE",
            "from customer",
            "where CUSTID = #{custid,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    Customer selectByPrimaryKey(Long custid);

    int updateByExampleSelective(@Param("record") Customer record, @Param("example") CustomerEx example);

    int updateByExample(@Param("record") Customer record, @Param("example") CustomerEx example);

    int updateByPrimaryKeySelective(Customer record);

    @Update({
            "update customer",
            "set CUSTGRADEID = #{custgradeid,jdbcType=INTEGER},",
            "EMAIL = #{email,jdbcType=VARCHAR},",
            "PASSWORD = #{password,jdbcType=VARCHAR},",
            "BORROWDAYS = #{borrowdays,jdbcType=INTEGER},",
            "MOBILE1 = #{mobile1,jdbcType=VARCHAR},",
            "MOBILE2 = #{mobile2,jdbcType=VARCHAR},",
            "PHONE = #{phone,jdbcType=VARCHAR},",
            "PRVID = #{prvid,jdbcType=INTEGER},",
            "LIBID = #{libid,jdbcType=INTEGER},",
            "CUSTCODE = #{custcode,jdbcType=VARCHAR},",
            "ADDRESS = #{address,jdbcType=VARCHAR},",
            "NAME = #{name,jdbcType=VARCHAR},",
            "ALIAS = #{alias,jdbcType=VARCHAR},",
            "RECOMMEMAIL = #{recommemail,jdbcType=VARCHAR},",
            "WEIBOACCOUNT = #{weiboaccount,jdbcType=VARCHAR},",
            "WEIXINACCOUNT = #{weixinaccount,jdbcType=VARCHAR},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "LASTSUCCESSLOGINTIME = #{lastsuccesslogintime,jdbcType=TIMESTAMP},",
            "LOGINFAILCOUNT = #{loginfailcount,jdbcType=INTEGER},",
            "BOOKCOINREWARDACCTBALANCE = #{bookcoinrewardacctbalance,jdbcType=DECIMAL},",
            "BOOKCOINACCTCASHBALANCE = #{bookcoinacctcashbalance,jdbcType=DECIMAL},",
            "DEPOSITBALANCE = #{depositbalance,jdbcType=DECIMAL}",
            "where CUSTID = #{custid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Customer record);
}
